
#include "NetBattleHandler.h"
#include "NetMsgHandler.h"

#include "CreatureManager.h"
#include "MapManager.h"
#include "BattleManager.h"
#include "GameDanger.h"

fint32		NetBattleCommandHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_BATTLE_COMMAND )

	GameTeam* team = player->GetTeam();
	
	BattleSession* session = F_NULL;

	if ( team )
	{
		session = gBattleManager->GetSession( (GamePlayer*)team->GetMember( 0 ) );
	}
	else
	{
		session = gBattleManager->GetSession( player );
	}
	
	if ( session )
	{
		session->AddCommand( player , msg->Command , msg->CommandPet );
	}
	

	return GAME_NO_ERROR;
}


fint32		NetBattleHandler( GamePlayer* player , netMsgHead* head )
{
    CHECKMSG( SEND_MSG_BATTLE )
	
    if ( player->IsFighting() )
	{
		return GAME_NO_ERROR;
	}

	GamePlayer* player1 = gCreatureManager->GetPlayer( msg->ID );

	if ( player == player1 )
	{
		player->AddDanger( GAME_DESTRUCTIVELY_DANGER );
		return GAME_NO_ERROR;
	}

	if ( !player1 )
	{
		return GAME_NO_ERROR;
	}

	if ( player1->IsFighting() )
	{
		return GAME_NO_ERROR;
	}

	gBattleManager->CreatBattle( player , player1 );

	return GAME_NO_ERROR;
}
